function getHospDeptLinkageSel(
    {
        hospSelName = "hospId",
        parentDeptSelName = "parentDeptId",
        deptSelName = "deptId",
        callback = Function(),
    }
) {
    const data = {};
    const hospDefValue = {name: "请选择医院", value: ""};
    const parentDeptDefVal = {name: "请选择大科室", value: ""};
    const deptDefVal = {name: "请选择子科室", value: ""};

    const $hospSel = $.getSelect(hospSelName, [
        hospDefValue
    ], ({value: hospId, name}) => {
        data[hospSelName] = hospId;
        data[parentDeptSelName] = "";
        data[deptSelName] = "";
        callback(data);

        refreshParentDeptSel(hospId);
        refreshDeptSel(null);
    });

    const $parentDeptSel = $.getSelect(parentDeptSelName, [
        parentDeptDefVal
    ], ({value: parentDeptId, name}) => {
        data[parentDeptSelName] = parentDeptId;
        data[deptSelName] = "";
        callback(data);
        refreshDeptSel(parentDeptId);
    });

    const $deptSel = $.getSelect(deptSelName, [
        deptDefVal
    ], ({value: deptId, name}) => {
        data[deptSelName] = deptId;
        callback(data);
    });

    queryHospList({}, ({Code, Message, Result}) => {
        if (Code !== 10000) {
            return;
        }
        $hospSel.refreshList(
            [
                hospDefValue,
                ...Result ? Result.map(({hospId, hospName}) => {
                    return {name: hospName, value: hospId}
                }) : []
            ]
        );
    });


    return {
        $hospSel, $parentDeptSel, $deptSel
    };


    function refreshParentDeptSel(hospId) {
        $parentDeptSel.setValue(parentDeptDefVal.value);

        if (!hospId) {
            $parentDeptSel.refreshList(
                [parentDeptDefVal]
            );
            return;
        }

        queryDeptList({
            hospId,
            bigDeptFlag: 1
        }, ({Code, Message, Result}) => {
            if (Code !== 10000) {
                return;
            }
            $parentDeptSel.refreshList(
                [
                    parentDeptDefVal,
                    ...Result ? Result.map(({deptId, deptName}) => {
                        return {name: deptName, value: deptId}
                    }) : []
                ]
            );
        })
    }

    function refreshDeptSel(parentDeptId) {
        $deptSel.setValue(deptDefVal.value);
        if (!parentDeptId) {
            $deptSel.refreshList(
                [deptDefVal]
            );
            return;
        }

        queryDeptList({
            parentDeptId,
        }, ({Code, Message, Result}) => {
            if (Code !== 10000) {
                return;
            }
            $deptSel.refreshList(
                [
                    deptDefVal,
                    ...Result ? Result.map(({deptId, deptName}) => {
                        return {name: deptName, value: deptId}
                    }) : []
                ]
            );
        })
    }


    function queryHospList(param, callback = Function()) {
        return $.sApi({
            data: param,
            showLoading:false,
            url: "/api/Hosp/queryHospList"
        }, callback)
    }

    function queryDeptList(param, callback = Function()) {
        return $.sApi({
            data: param,
            showLoading:false,
            url: "/api/Dept/queryDeptList"
        }, callback)
    }
}